script_enemy_main{

let shoottime=180;
let speed=1.5;

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];

let character="Masahiro";
let cutin=character;
let dispelled=0;
let spellcards=4;
let spellcardnumber=64;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEmagics5=("\script\SoundEffects\magics5.wav");
let SEshotb1=("\script\SoundEffects\shotb1.wav");

let BG1=("\script\Images\BackgroundLayers\Nightmare2.png");
let BG2=("\script\Images\BackgroundLayers\Midori3.png");
let GRboss=("\script\Images\CharacterSprites\"~character~".png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsNightmare1.txt");

	LoadSE("\script\SoundEffects\magics5.wav");
	LoadSE("\script\SoundEffects\shotb1.wav");
	
	LoadGraphic("\script\Images\CharacterSprites\"~character~".png");
	LoadGraphic("\script\Images\BackgroundLayers\Nightmare2.png");
	LoadGraphic("\script\Images\BackgroundLayers\Midori3.png");

	SetScore(1000000);
	SetLife(500);
	SetTimer(75);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(150,150,150,150);

if(GetCommonData("BombOn")==0){ damagerate=10; if(shoottime<=40){damagerate=20; } }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate,damagerate);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }
SpellcardName("[Dreamcatcher]",spellcardnumber);

HealthBar();
Portrait(cutin,1);


if(frame==shoottime){
let angle=GetAngleToPlayer;
	loop(12){
	CreateShot02(GetX+12,GetY-25,4,angle,-0.04,2,22,0);
	angle+=360/12;
	}
frame=0;
usespell=25;
if(shoottime>40){ shoottime-=10; }
PlaySE(SEshotb1);
}

if((time+210)%270==0 && time>60){ if(speed<3.5){ speed+=0.3; } }

if((time+210)%270==0 && time>=60){
let angle=rand(0,360);
	loop(10){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+25*cos(angle),(GetY-20)+25*sin(angle));
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,11);
	Obj_SetAlpha(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=1.5;
	angle+=360/10;
	}
angle+=360/20;
	loop(10){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+25*cos(angle),(GetY-20)+25*sin(angle));
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,12);
	Obj_SetAlpha(shot1,0);
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=-1.5;
	angle+=360/10;
	}
usespell=-90;
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+angle1[i]);
		if(timer1[i]%5==0){
		let shotx=0;
		let shoty=1;
			if(angle1[i]>0){
					CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),15);
					SetShotDataA(shotx,0,0,Obj_GetAngle(bullet1[i]),0,0,0,11);
					SetShotDataA(shotx,120,0,Obj_GetAngle(bullet1[i]),0,speed/90,speed,11);
					FireShot(shotx);
			}
			if(angle1[i]<0){
					CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),15);
					SetShotDataA(shotx,0,0,Obj_GetAngle(bullet1[i]),0,0,0,12);
					SetShotDataA(shotx,120,0,Obj_GetAngle(bullet1[i]),0,speed/90,speed,12);
					FireShot(shotx);
			}
		PlaySE(SEmagics5);
		}
	if(timer1[i]==215){ Obj_Delete(bullet1[i]); }
	timer1[i]=timer1[i]+1;
	}
i++;
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/2);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/8);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(120,120,120);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	SetCommonData("NightmareSpellcards",8);
	NewPointData(spellcardnumber,6);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}